/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.colswe.testingProject.control;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collection;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import org.colswe.testingProject.entity.Person;
import org.colswe.testingProject.view.EditUserPanel;
import org.colswe.testingProject.view.LoginWindow;

/**
 *
 * @author Leonardo Bohórquez
 */
public class CRUDUsersControl {

    private DefaultTableModel tblmResults;
    private PersonControl pc;
    EditUserPanel pnlEdit;

    public DefaultTableModel showResults() {
        pc = new PersonControl();

        tblmResults = new DefaultTableModel(new Object[][]{}, new String[]{"Rol", "Usuario", "Editar", "Eliminar"}) {
            boolean[] canEdit = new boolean[]{
                false, false, false, false
            };

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        };

        Object[] row = new Object[4];
        Collection<Person> persons = pc.readAll();
        if (persons != null) {
            for (Person p : persons) {//buscar la manera de guardar el objeto directamente
                JButton cmdEdit = new JButton("Editar");
                JButton cmdDelete = new JButton("Eliminar");

                row[0] = p.getRole();
                row[1] = p.getUserName();
                row[2] = cmdEdit;
                row[3] = cmdDelete;
                tblmResults.addRow(row);
            }
        }
        return tblmResults;
    }
}
